package com.dycx.user.converter;

import java.time.LocalDateTime;

import cn.hutool.core.bean.BeanUtil;
import com.dycx.common.vendor.oss.AliyunOss;
import com.dycx.user.enums.SellerStatusEnum;
import lombok.Data;

import java.io.Serializable;

import org.springframework.beans.BeanUtils;

import java.util.ArrayList;
import java.util.List;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dycx.user.entity.SellerDO;
import com.dycx.user.vo.SellerVO;
import com.dycx.user.dto.SellerDTO;

/**
 * 商家(Seller)实体转换类
 *
 * @author wuzongbin
 * @since 2023-11-08 16:46:03
 */


@Data
public class SellerConverter implements Serializable {
    public static SellerDO dtoToEntity(SellerDTO dto) {
        if (dto == null) return null;
        SellerDO entity = BeanUtil.toBean(dto, SellerDO.class);
        entity.setCompanyBusinessLicense(AliyunOss.delDomain(entity.getCompanyBusinessLicense()));
        entity.setBanner(AliyunOss.delDomain(entity.getBanner()));
        return entity;
    }

    public static SellerVO entityToVo(SellerDO entity) {
        if (entity == null) return null;
        SellerVO vo = BeanUtil.toBean(entity, SellerVO.class);

        SellerStatusEnum sellerStatusEnum = SellerStatusEnum.getCode(vo.getCheckStatus());
        vo.setCheckStatusName(sellerStatusEnum.getName());
        vo.setCompanyBusinessLicense(AliyunOss.addDomain(vo.getCompanyBusinessLicense()));
        vo.setBanner(AliyunOss.addDomain(vo.getBanner()));
        return vo;
    }

    public static List<SellerVO> entityToVoList(List<SellerDO> entityList) {
        List<SellerVO> voList = new ArrayList<>();
        for (SellerDO entity : entityList) {
            voList.add(entityToVo(entity));
        }
        return voList;
    }

    public static Page<SellerVO> entityToVoPage(Page<SellerDO> page) {

        List<SellerVO> newRecords = new ArrayList<>();

        List<SellerDO> records = page.getRecords();
        for (SellerDO entity : records) {
            newRecords.add(entityToVo(entity));
        }

        Page<SellerVO> voPage = new Page<>();
        voPage.setRecords(newRecords);
        voPage.setPages(page.getPages());
        voPage.setTotal(page.getTotal());
        voPage.setSize(page.getSize());
        voPage.setCurrent(page.getCurrent());

        return voPage;
    }

}
